package org.stvd.entities.oauth;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Min;

import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.format.annotation.DateTimeFormat;
import org.stvd.core.annotation.serializer.DateTimeSerializer;
import org.stvd.entities.base.BaseEntity;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;

/**
 * Oauth客户端信息-实体类
 * @author houzx
 */
@Entity
@Table(name = "oauth_client_details")
public class OauthClientDetails extends BaseEntity{

    private static final long serialVersionUID = -1684166462704886695L;

    /**
     * 客户端ID
     */
    @Id
    @Column(name = "client_id", nullable = false)
    @NotEmpty(message="客户端ID不能为空")
    private String clientId = "";
    
    /**
     * 资源ID
     */
    @Column(name = "resource_ids")
    private String resourceIds = "";
    
    /**
     * 客户端密钥
     */
    @Column(name = "client_secret")
    private String clientSecret = "";
    
    /**
     * 访问权限{read,write}
     */
    @Column(name = "scope")
    private String scope = "";
    
    /**
     * 授权类型{password,authorization_code,client_credentials,refresh_token,implicit}
     */
    @Column(name = "authorized_grant_types")
    private String authorizedGrantTypes = "";
    
    /**
     * 重定向地址
     */
    @Column(name = "web_server_redirect_uri")
    private String webServerRedirectUri = "";
    
    /**
    * 认证权限{ROLE_XXX}
    */
    @Column(name = "authorities")
    private String authorities = "";
    
    /**
     * 授权Token有效期限
     */
    @Column(name = "access_token_validity")
    @Min(value = 1, message = "有效期限最小为1")
    private Integer accessTokenValidity = null;
    
    /**
     * 刷新Token有效期限
     */
    @Column(name = "refresh_token_validity")
    @Min(value = 1, message = "刷新期限最小为1")
    private Integer refreshTokenValidity = null;
    
    /**
     * 附属信息
     */
    @Column(name = "additional_information")
    private String additionalInformation = "";
    
    /**
     * 存档
     */
    @Column(name = "archived")
    private Integer archived = 0;
    
    /**
     * 信任
     */
    @Column(name = "trusted")
    private Integer trusted = 0;
    
    /**
     * 自动批准
     */
    @Column(name = "autoapprove")
    private String autoApprove = "false";
    
    /**
     * 创建时间
     */
    @Column(name = "create_time", nullable = false)
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = DateTimeSerializer.class)
    private Date createTime = null;
    
    @Transient
    private String oldClientId = "";

    @Column(name = "client_name")
    private String clientName = "";
    
    @Column(name = "client_intro")
    private String clientIntro = "";
    
    @Column(name = "client_url")
    private String clientUrl = "";
    
    @Column(name = "username")
    private String username = "";
    
    @Column(name = "linkman")
    private String linkman = "";
    
    @Column(name = "linktel")
    private String linktel = "";
    
    public String getClientId() {
        return clientId;
    }

    public void setClientId(String clientId) {
        this.clientId = clientId;
    }

    public String getResourceIds() {
        return resourceIds;
    }

    public void setResourceIds(String resourceIds) {
        this.resourceIds = resourceIds;
    }

    public String getClientSecret() {
        return clientSecret;
    }

    public void setClientSecret(String clientSecret) {
        this.clientSecret = clientSecret;
    }

    public String getScope() {
        return scope;
    }

    public void setScope(String scope) {
        this.scope = scope;
    }

    public String getAuthorizedGrantTypes() {
        return authorizedGrantTypes;
    }

    public void setAuthorizedGrantTypes(String authorizedGrantTypes) {
        this.authorizedGrantTypes = authorizedGrantTypes;
    }

    public String getWebServerRedirectUri() {
        return webServerRedirectUri;
    }

    public void setWebServerRedirectUri(String webServerRedirectUri) {
        this.webServerRedirectUri = webServerRedirectUri;
    }

    public String getAuthorities() {
        return authorities;
    }

    public void setAuthorities(String authorities) {
        this.authorities = authorities;
    }

    public Integer getAccessTokenValidity() {
        return accessTokenValidity;
    }

    public void setAccessTokenValidity(Integer accessTokenValidity) {
        this.accessTokenValidity = accessTokenValidity;
    }

    public Integer getRefreshTokenValidity() {
        return refreshTokenValidity;
    }

    public void setRefreshTokenValidity(Integer refreshTokenValidity) {
        this.refreshTokenValidity = refreshTokenValidity;
    }

    public String getAdditionalInformation() {
        return additionalInformation;
    }

    public void setAdditionalInformation(String additionalInformation) {
        this.additionalInformation = additionalInformation;
    }

    public Integer getArchived() {
        return archived;
    }

    public void setArchived(Integer archived) {
        this.archived = archived;
    }

    public Integer getTrusted() {
        return trusted;
    }

    public void setTrusted(Integer trusted) {
        this.trusted = trusted;
    }

    public String getAutoApprove() {
        return autoApprove;
    }

    public void setAutoApprove(String autoApprove) {
        this.autoApprove = autoApprove;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getOldClientId() {
        return oldClientId;
    }

    public void setOldClientId(String oldClientId) {
        this.oldClientId = oldClientId;
    }

    public String getClientName() {
        return clientName;
    }

    public void setClientName(String clientName) {
        this.clientName = clientName;
    }

    public String getClientIntro() {
        return clientIntro;
    }

    public void setClientIntro(String clientIntro) {
        this.clientIntro = clientIntro;
    }

    public String getClientUrl() {
        return clientUrl;
    }

    public void setClientUrl(String clientUrl) {
        this.clientUrl = clientUrl;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getLinkman() {
        return linkman;
    }

    public void setLinkman(String linkman) {
        this.linkman = linkman;
    }

    public String getLinktel() {
        return linktel;
    }

    public void setLinktel(String linktel) {
        this.linktel = linktel;
    }
}
